/**
 * Created by fly on 2017/1/16.
 */
$(function () {

    validForm();

    $("#btnLogin").click(function () {
        if ($("#form").valid()) {
            $.ajax({
                type: "post",
                url: ctx+"/user/login",
                dataType: "json",
                data: {
                    loginCode: $("#username").val().trim(),
                    password: $("#password").val().trim()
                },
                success: function (msg) {
                    if (msg.code == 200) {
                        window.sessionStorage.setItem('managerUser', $("#username").val().trim())
                        window.location.href = "resources/views/index.html";
                    } else {
                        alert(msg.msg);
                    }
                }
            });
        }
    });
});


function validForm() {

    $("#form").validate({
        debug: true,
        rules: {
            username: {
                required: true,
                rangelength: [2,20]
            },
            password: {
                required: true,
                rangelength: [1,16]
            }
        }
    });
}

